/*
 * Copyright 2007. Mount Sinai Hospital, Toronto, Canada.
 * 
 * Licensed under the GNU Lesser General Public License, Version 2. You
 * can find a copy of the license at:
 * 
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
 * 
 * IN NO EVENT SHALL MOUNT SINAI HOSPITAL BE LIABLE TO ANY PARTY FOR DIRECT, 
 * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST 
 * PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, 
 * EVEN IF MOUNT SINAI HOSPITAL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
 * DAMAGE.
 * 
 * MOUNT SINAI HOSPITAL SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF 
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND 
 * ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". 
 * MOUNT SINAI HOSPITAL HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 
 * UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 
 */
package com.sinai.mshab.client.ui.label;

import com.google.gwt.user.client.ui.Label;
import com.sinai.mshab.client.MSHABConfig;
import com.sinai.mshab.client.ui.FormComponent;

/**
 * <code>ErrorLabel</code> is used in making error {@link Label}s that are
 * usually attached to {@link FormComponent}s. <code>ErrorLabel</code>
 * provides a layer of abstraction between regular <code>Label</code>s and
 * labels that are bound for use as error messages. This removes duplicate code
 * because CSS styles are automatically set and the <code>ErrorLabel</code> is
 * automatically hidden.
 * 
 * @author Arthur Kalmenson
 */
public class ErrorLabel extends Label {
	/**
	 * Creates a new <code>ErrorLabel</code> using the provided text. The CSS
	 * style is retrieved from {@link MSHABConfig}.
	 * 
	 * @param text
	 *            the text that this label will show.
	 */
	public ErrorLabel(String text) {
		super(text);
		initialize();
	}

	/**
	 * Creates a new <code>ErrorLabel</code> using the provided text and set's
	 * word wrapping to <code>wordWrap</code>. The CSS style is retrieved
	 * from {@link MSHABConfig}.
	 * 
	 * @param text
	 *            the text that this label will show.
	 * @param wordWrap
	 *            true to wrap words and false otherwise.
	 */
	public ErrorLabel(String text, boolean wordWrap) {
		super(text, wordWrap);
		initialize();
	}

	/**
	 * Initialize the widget by adding the appropriate CSS style and making it
	 * invisible.
	 */
	private void initialize() {
		this.setStyleName(MSHABConfig.getCSSErrorLabel());
		this.setVisible(false);
	}
}
